package org.goface.rpc.pipeline;

import org.goface.rpc.MessageContext;

import com.goface.rpc.conf.ServiceConfigure;
import com.google.common.net.HostAndPort;

public abstract class RouterHandler extends ServiceHandlerAdaptor {

    @Override
    public void sendRequest(ServiceHandlerContext context, MessageContext messageContext) throws Throwable {
        HostAndPort address = findServiceAddress(messageContext);
        messageContext.getProperties().put(ServiceConfigure.SERVICE_CLIENT_SERVICE_ADDRESS, address);
        context.getNext().getHandler().sendRequest(context.getNext(), messageContext);
    }

    public abstract HostAndPort findServiceAddress(MessageContext messageContext);

}
